home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / Ant Movie Catalog 3.5.0.2 / amc_install.exe / {app} / Scripts / IMDB.ifs < prev    next >
Text File  |  2005-05-29  |  27KB  |  731 lines

  1. (***************************************************
  2.  
  3. Ant Movie Catalog importation script
  4. www.antp.be/software/moviecatalog/
  5.  
  6. [Infos]
  7. Authors=Antoine Potten, KaraGarga
  8. Title=IMDB
  9. Description=Import data & picture from IMDB (optional image from Amazon)
  10. Site=us.imdb.com
  11. Language=EN
  12. Version=2.04
  13. Requires=3.5.0
  14. Comments=Based on the script made for version 3.x by Antoine Potten, Danny Falkov, Kai Blankenhorn, lboregard, Ork, Trekkie, Youri Heijnen
  15. License=This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
  16. GetInfo=1
  17.  
  18. [Options]
  19. ImageKind=0|1|0=No image|1=IMDB small image, from the main movie page|2=IMDB large image if found, else small image|3=IMDB large image if found, else try all other links|4=Cover from "Merchandising Link" page, else "DVD detail" page, else small image|5=Cover from "DVD detail" page, else "Merchandising Link", else small image|6=Try to get image from Amazon (does not work very well for the moment)
  20. BatchMode=0|0|0=Normal working mode, prompts user when needed|1=Does not display any window, takes the first movie found|2=Same as 1, but it uses the URL field if available to update movie information
  21. PopularSearches=1|1|0=Do not use the popular searches page, directly show full search results|1=Show popular searches first, I'll click on "Find more" if needed (much faster)
  22. ActorsLayout=4|2|0=Only actor names, separated by commas|1=Only actor names, separated by linebreaks|2=Actors names with character names between parenthesis separated by commas|3=Actors names with character names between parenthesis separated by linebreaks|4=Actor names like on IMDB page, with "...." and separated by linebreaks
  23. MultipleValuesCountry=1|0|0=Only take first value for Country|1=Take full list, separated by commas|2=Take full list, separated by slashes
  24. MultipleValuesCategory=1|0|0=Only take first value for Category|1=Take full list, separated by commas|2=Take full list, separated by slashes
  25. MultipleValuesLanguages=1|0|0=Only take first value for Languages|1=Take full list, separated by commas|2=Take full list, separated by slashes
  26. DescriptionSelection=0|1|0=Take the short summary, from main page (faster)|1=Show a list of available summaries|2=Take the longest summary
  27. GetTagline=1|0|0=Do not get tagline|1=Put it in Description field, before the summary|2=Put it in the Comment field, before the comments
  28. Trivia=0|0|0=Do not import trivia|1=Import trivia to Description field, after the summary|2=Import trivia to Comments field, after the comments
  29. AmazonReview=0|0|0=Do not get Amazon Review|1=Get Amazon Review
  30. CommentType=0|0|0=Standard Type (Only one comment from main page)|1=Detailed Type (10 most useful comments from comments page)|2=No user comment
  31. Awards=0|0|0=Do not import awards|1=Import awards to Description field, after the summary|2=Import awards to Comments field, after comments
  32.  
  33. ***************************************************)
  34.  
  35. program IMDB;
  36.  
  37. uses
  38.   StringUtils1, Debug;
  39.  
  40. var
  41.   MovieName: string;
  42.   MovieURL: string;
  43.   MovieNumber: string;
  44.  
  45. // ***** analyzes the results page that asks to select a movie from a list *****
  46.  
  47. procedure AnalyzeResultsPage(Address: string);
  48. var
  49.   PageText: string;
  50.   Value: string;
  51. begin
  52.   PageText := GetPage(Address);
  53.   if pos('<title>IMDb', PageText) = 0 then
  54.   begin
  55.     AnalyzeMoviePage(PageText)
  56.   end else
  57.   begin
  58.     if Pos('<b>No Matches.</b>', PageText) > 0 then
  59.     begin
  60.       if GetOption('BatchMode') = 0 then
  61.         ShowMessage('No movie found for this search');
  62.       Exit;
  63.     end;
  64.     if GetOption('BatchMode') = 0 then
  65.     begin
  66.       PickTreeClear;
  67.       repeat
  68.         Value := TextBefore(PageText, '<ol>', '<b>');
  69.         if Value <> '' then
  70.         begin
  71.           HTMLRemoveTags(Value);
  72.           HTMLDecode(Value);
  73.           PickTreeAdd(Value, '');
  74.         end;
  75.         Value := TextBetween(PageText, '<ol>', '</ol>');
  76.         PageText := RemainingText;
  77.       until not AddMovieTitles(Value);
  78.       Value := TextBefore(PageText, '"><b>more titles</b></a>', '<a href="');
  79.       if Value <> '' then
  80.         PickTreeMoreLink('http://us.imdb.com' + Value);
  81.       if PickTreeExec(Address) then
  82.         AnalyzeResultsPage(Address);
  83.     end
  84.     else
  85.     begin
  86.       Value := TextBetween(TextBetween(PageText, '<ol>', '</ol>'), '<li>', '</li>');
  87.       if Value <> '' then
  88.         AnalyzeResultsPage(TextBetween(Value, '<a href="', '">'));
  89.     end;
  90.   end;
  91. end;
  92.  
  93. // ***** adds the titles contained in <ol>'s items *****
  94.  
  95. function AddMovieTitles(List: string): Boolean;
  96. var
  97.   Value: string;
  98.   Address: string;
  99. begin
  100.   Result := False;
  101.   Value := TextBetween(List, '<li>', '</li>');
  102.   List := RemainingText;
  103.   while Value <> '' do
  104.   begin
  105.     Address := TextBetween(Value, '<a href="', '">');
  106.     HTMLRemoveTags(Value);
  107.     HTMLDecode(Value);
  108.     PickTreeAdd(Value, 'http://us.imdb.com' + Address);
  109.     Result := True;
  110.     Value := TextBetween(List, '<li>', '</li>');
  111.     List := RemainingText;
  112.   end;
  113. end;
  114.  
  115. // ***** analyzes the page containing movie information *****
  116.  
  117. procedure AnalyzeMoviePage(PageText: string);
  118. var
  119.   Value, Value2, Value3, FullValue: string;
  120.   p: Integer;
  121. begin
  122.   MovieNumber := TextBetween(PageText, '<input type="hidden" name="auto" value="legacy/title/tt', '/"><input');
  123.   MovieURL := 'http://imdb.com/title/tt' + MovieNumber;
  124.   // URL
  125.   if CanSetField(fieldURL) then
  126.     SetField(fieldURL, MovieURL);
  127.   // Original Title & Year
  128.   if CanSetField(fieldOriginalTitle) or CanSetField(fieldYear) then
  129.   begin
  130.     Value := TextBetween(PageText, '<title>', '</title>');
  131.     Value2 := TextBefore(Value, ' (', '');
  132.     Value := RemainingText;
  133.     HTMLDecode(Value2);
  134.     if CanSetField(fieldOriginalTitle) then
  135.       SetField(fieldOriginalTitle, Value2);
  136.     if Pos('/', Value) > 0 then
  137.       Value2 := TextBefore(Value, '/', '')
  138.     else
  139.       Value2 := TextBefore(Value, ')', '');
  140.     if CanSetField(fieldYear) then
  141.       SetField(fieldYear, Value2);
  142.   end;
  143.   // Rating
  144.   if CanSetField(fieldRating) then
  145.   begin
  146.     Value := TextBetween(PageText, '/rating-stars/', '/rating-vote/');
  147.     SetField(fieldRating, TextBetween(Value, '<b>', '/'));
  148.   end;
  149.   // Picture
  150.   if CanSetPicture then
  151.   begin
  152.     case GetOption('ImageKind') of
  153.       1:  ImportSmallPicture(PageText);
  154.       2:  if not ImportLargePicture('http://us.imdb.com/gallery/ss/' + MovieNumber) then
  155.             ImportSmallPicture(PageText);
  156.       3:  if not ImportLargePicture('http://us.imdb.com/gallery/ss/' + MovieNumber) then
  157.             if not ImportMerchandisingPicture(PageText) then
  158.               if not ImportDvdDetailsPicture(PageText) then
  159.                 ImportSmallPicture(PageText);
  160.       4:  if not ImportMerchandisingPicture(PageText) then
  161.               if not ImportDvdDetailsPicture(PageText) then
  162.                 ImportSmallPicture(PageText);
  163.       5:  if not ImportDvdDetailsPicture(PageText) then
  164.               if not ImportMerchandisingPicture(PageText) then
  165.                 ImportSmallPicture(PageText);
  166.       6:  if not ImportAmazonPicture(PageText) then
  167.             ImportSmallPicture(PageText);
  168.     end;
  169.   end;
  170.   // Director
  171.   if CanSetField(fieldDirector) then
  172.   begin
  173.     Value := TextBetween(PageText, '<b class="blackcatheader">Directed by</b><br>', '<br>' + #13);
  174.     Value := StringReplace(TextAfter(Value, '">'), '<br>', ', ');
  175.     HTMLRemoveTags(Value);
  176.     HTMLDecode(Value);
  177.     SetField(fieldDirector, Value);
  178.   end;
  179.   // Actors
  180.   if CanSetField(fieldActors) then
  181.   begin
  182.     Value := TextBetween(PageText, 'ast overview', '</div>');
  183.     if Value = '' then
  184.       Value := TextBetween(PageText, 'redited cast', '</div>');
  185.     if Value <> '' then
  186.     begin
  187.       Value := TextAfter(Value, '</tr> ');
  188.       FullValue := '';
  189.       case GetOption('ActorsLayout') of
  190.         0, 1:
  191.           while Pos('<tr>', Value) > 0 do
  192.           begin
  193.             Value2 := TextBetween(Value, '<tr>', '</tr>');
  194.             Value := RemainingText;
  195.             if Pos('rest of cast', Value2) > 0 then
  196.               Continue;
  197.             if Pos('<a href="fullcredits">(more)</a>', Value2) > 0 then
  198.               Break;
  199.             if FullValue <> '' then
  200.               FullValue := FullValue + #13#10;
  201.             FullValue := FullValue + TextBefore(Value2, '</td>', '');
  202.           end;
  203.         2, 3:
  204.           while Pos('<tr>', Value) > 0 do
  205.           begin
  206.             Value2 := TextBetween(Value, '<tr>', '</tr>');
  207.             Value := RemainingText;
  208.             if Pos('rest of cast', Value2) > 0 then
  209.               Continue;
  210.             if Pos('<a href="fullcredits">(more)</a>', Value2) > 0 then
  211.               Break;
  212.             if FullValue <> '' then
  213.               FullValue := FullValue + #13#10;
  214.             FullValue := FullValue + TextBefore(Value2, '</td>', '');
  215.             Value2 := TextBetween(RemainingText, '<td valign="top">', '</td>');
  216.             if Value2 <> '' then
  217.               FullValue := FullValue + ' (as ' + Value2 + ')';
  218.           end;
  219.         4:
  220.           begin
  221.             FullValue := TextBefore(Value, '</tr><tr><td colspan="2">', '');
  222.             if FullValue = '' then
  223.               FullValue := Value;
  224.             FullValue := StringReplace(FullValue, ' <tr><td align="center" colspan="3"><small>rest of cast listed alphabetically:</small></td></tr> ', '');
  225.             FullValue := StringReplace(FullValue, '</tr>', #13#10);
  226.           end;
  227.       end;
  228.       HTMLRemoveTags(FullValue);
  229.       HTMLDecode(FullValue);
  230.       case GetOption('ActorsLayout') of
  231.         0, 2:
  232.           FullValue := StringReplace(FullValue, #13#10, ', ');
  233.       end;
  234.       SetField(fieldActors, FullValue);
  235.     end;
  236.   end;
  237.   //Country
  238.   if CanSetField(fieldCountry) then
  239.   begin
  240.     SetField(fieldCountry, ImportList(PageText, GetOption('MultipleValuesCountry'), '/Countries/'));
  241.   end;
  242.   //Category
  243.   if CanSetField(fieldCategory) then
  244.   begin
  245.     SetField(fieldCategory, ImportList(PageText, GetOption('MultipleValuesCategory'), '/Genres/'));
  246.   end;
  247.   // Language
  248.   if CanSetField(fieldLanguages) then
  249.   begin
  250.     SetField(fieldLanguages, ImportList(PageText, GetOption('MultipleValuesLanguages'), '/Languages/'));
  251.   end;
  252.   // Description
  253.   if CanSetField(fieldDescription) then
  254.   begin
  255.     Value := TextBetween(PageText, '<b class="ch">Plot Outline:</b>', '<br><br>');
  256.     if Value = '' then
  257.       Value := TextBetween(PageText, '<b class="ch">Plot Summary:</b>', '<br><br>');
  258.     if Value <> '' then
  259.       SetField(fieldDescription, ImportSummary(Value));
  260.     // Amazon.com Description
  261.     if (GetOption('AmazonReview') > 0) then
  262.     begin
  263.       Value := TextAfter(PageText, '<a href="amazon">');
  264.       if Value <> '' then
  265.       begin
  266.         Value := GetField(fieldURL);
  267.         PageText := GetPage(Value+'/amazon');
  268.         Value := TextBetween(PageText, 'Amazon.com video review:', '<div align="center"> <!--');
  269.         Value2 := TextBetween(PageText, '<title>', '</title>');
  270.         Value := StringReplace(Value, #13#10, '');
  271.         Value := StringReplace(Value, '  ', '');
  272.         Value := StringReplace(Value, '<p>', #13#10+'');
  273.         HTMLRemoveTags(Value);
  274.         HTMLRemoveTags(Value2);
  275.         Value2 := AnsiUpperCase(Value2);
  276.         SetField(fieldDescription, GetField(fieldDescription) + #13#10 + #13#10 + Value2 + ': ' + Value);
  277.       end;
  278.     end;
  279.   end;
  280.   // Length
  281.   if CanSetField(fieldLength) then
  282.   begin
  283.     Value := TextBetween(PageText, '<b class="ch">Runtime:</b>' + #13#10, ' ');
  284.     if Value <> '' then
  285.     begin
  286.       if Pos(':', Value) > 0 then
  287.         SetField(fieldLength, TextAfter(Value, ':'))
  288.       else
  289.         SetField(fieldLength, Value);
  290.     end;
  291.   end;
  292.   // Writer (Producer Field)
  293.   if CanSetField(fieldProducer) then
  294.   begin
  295.     Value := TextBetween(PageText, '<b class="blackcatheader">Writing credits</b>', '<br>' + #13#10 + '<br>');
  296.     if Value <> '' then
  297.     begin
  298.       Value := StringReplace(Value, '(<a href="/wga">WGA</a>)', '');
  299.       Value := StringReplace(TextAfter(Value, '">'), '<br>', ', ');
  300.       HTMLRemoveTags(Value);
  301.       HTMLDecode(Value);
  302.       Value := Trim(StringReplace(Value, '...,  (more)', ''));
  303.       Value := Trim(StringReplace(Value, ',  (more)', ''));
  304.       SetField(fieldProducer, Value)
  305.    end;
  306.   end;
  307.   // AKA Name
  308.   if CanSetField(fieldTranslatedTitle) then
  309.   begin
  310.     Value := TextBetween(PageText, '<b class="ch">Also Known As:</b><br>', '<br>' + #13#10 + '<b');
  311.     if Value <> '' then
  312.     begin
  313.       Value := StringReplace(Value, ' <br>', ', ');
  314.       HTMLRemoveTags(Value);
  315.       HTMLDecode(Value);
  316.       SetField(fieldTranslatedTitle, Value)
  317.    end;
  318.   end;
  319.   // Comments
  320.   if CanSetField(fieldComments) then
  321.   begin
  322.     if (GetOption('CommentType') = 1) then
  323.     begin
  324.       Value := TextAfter(PageText,'<a href="usercomments">');
  325.       if Value <> '' then
  326.       begin
  327.         Value := GetField(fieldURL);
  328.         FullValue := GetPage(Value+'/usercomments');
  329.         Value := TextBetween(FullValue, '<hr size="1" noshade="1">', '<hr size="1" noshade="1">');
  330.         Value2 := TextBetween(FullValue, '<title>', '</title>');
  331.         Value := StringReplace(Value, #13#10, ' ');
  332.         Value := StringReplace(Value, '</b>, <small>', #13#10+'Date: ');
  333.         Value := StringReplace(Value, '</small><br>', #13#10);
  334.         Value := StringReplace(Value, '</b>', #13#10);
  335.         Value := StringReplace(Value, '<br><br>', #13#10);
  336.         Value := StringReplace(Value, '<br>', #13#10);
  337.         Value := StringReplace(Value, '<p>', #13#10);
  338.         Value := StringReplace(Value, 'Add another comment', '');
  339.         Value := StringReplace(Value, '  ', '');
  340.         Value := StringReplace(Value, 'Was the above comment useful to you?', #13#10+'___________'+#13#10);
  341.         HTMLRemoveTags(Value);
  342.         HTMLDecode(Value);
  343.         HTMLRemoveTags(Value2);
  344.         HTMLDecode(Value2);
  345.         Value2 := AnsiUpperCase(Value2);
  346.         Value := StringReplace(Value, ' Author:', 'Author:');
  347.         SetField(fieldComments, Value2 + ':' + #13#10 + Value);
  348.       end;
  349.     end
  350.     else
  351.     if (GetOption('CommentType') = 0) then
  352.     begin
  353.       Value := TextAfter(PageText, '/comments">');
  354.       if Value <> '' then
  355.       begin
  356.         Value := TextBetween(Value, '<p>', '</p>');
  357.         Value := StringReplace(Value, #13#10, ' ');
  358.         Value := StringReplace(Value, '<br>', #13#10);
  359.         HTMLRemoveTags(Value);
  360.         HTMLDecode(Value);
  361.         Value := Trim(Value);
  362.         while Pos('  ', Value) > 0 do
  363.           Value := StringReplace(Value, '  ', ' ');
  364.         while Pos(#13#10, Value) = 1 do
  365.           Delete(Value, 1, 2);
  366.         SetField(fieldComments, Value);
  367.       end;
  368.     end;
  369.   end;
  370.   // TagLine
  371.   if GetOption('GetTagline') > 0 then
  372.   begin
  373.     Value := TextBetween(PageText, 'Tagline:</b>', #13);
  374.     if Pos('<a', Value) > 0 then
  375.       Value := TextBefore(Value, '<a', '');
  376.     HTMLRemoveTags(Value);
  377.     HTMLDecode(Value);
  378.     Value := Trim(Value);
  379.     if Value <> '' then
  380.     begin
  381.       if Copy(Value, 1, 1) <> '"' then
  382.         Value := '"' + Value + '"';
  383.       case GetOption('GetTagline') of
  384.         1:
  385.           begin
  386.             if GetField(fieldDescription) <> '' then
  387.               Value := Value + #13#10 + #13#10 + GetField(fieldDescription);
  388.             SetField(fieldDescription, Value);
  389.           end;
  390.         2:
  391.           begin
  392.             if GetField(fieldComments) <> '' then
  393.               Value := Value + #13#10 + #13#10 + GetField(fieldComments);
  394.             SetField(fieldComments, Value);
  395.           end;
  396.       end;
  397.     end;
  398.   end;
  399.   // Trivia
  400.   if GetOption('Trivia') > 0 then
  401.   begin
  402.     Value := TextAfter(PageText, '<a href="trivia">');
  403.     if Value <> '' then
  404.     begin
  405.       sleep(50);
  406.       Value := GetField(fieldURL);
  407.       FullValue := GetPage(Value+'/trivia');
  408.       Value := TextBetween(FullValue, '<ul class="trivia">', '<div align="center"> <!--');
  409.       Value2 := TextBetween(FullValue, '<title>', '</title>');
  410.       Value := StringReplace(Value, #13#10, '');
  411.       Value := StringReplace(Value, '  ', '');
  412.       Value := StringReplace(Value, '<li>', #13#10 + '- ');
  413.       HTMLRemoveTags(Value);
  414.       HTMLDecode(Value);
  415.       HTMLRemoveTags(Value2);
  416.       HTMLDecode(Value2);
  417.       Value2 := AnsiUpperCase(Value2);
  418.       case GetOption('Trivia') of
  419.         1:
  420.           begin
  421.             if GetField(fieldDescription) <> '' then
  422.               Value := GetField(fieldDescription) + #13#10 + #13#10 + 'IMDB ' + Value2 + ': ' + Value
  423.             else
  424.               Value :=  'IMDB ' + Value2 + ': ' + Value;
  425.             SetField(fieldDescription, Value);
  426.           end;
  427.         2:
  428.           begin
  429.             if GetField(fieldComments) <> '' then
  430.               Value := GetField(fieldComments) + #13#10 + #13#10 + 'IMDB ' + Value2 + ': ' + Value
  431.             else
  432.               Value :=  'IMDB ' + Value2 + ': ' + Value;
  433.             SetField(fieldComments, Value);
  434.           end;
  435.       end;
  436.     end;
  437.   end;
  438.   // Awards
  439.   if (GetOption('Awards') > 0) then
  440.   begin
  441.     Value := TextAfter(PageText, '<a href="awards">');
  442.     if Value <> '' then
  443.     begin
  444.       Value := GetField(fieldURL);
  445.       PageText := GetPage(Value+'/awards');
  446.       Value2 := TextBetween(PageText, ' <h1>', '</h1>');
  447.       Value := TextBetween(PageText, '<table cellspacing="2" cellpadding="2" border="1" width="95%">', '<!--');
  448.       Value := StringReplace(Value, '<big>', '- ');
  449.       Value := StringReplace(Value, '<tr><th>Year</th><th>Result</th><th>Award</th><th>Category/Recipient(s)</th></tr>', '');
  450.       HTMLDecode(Value);
  451.       HTMLRemoveTags(Value);
  452.       HTMLDecode(Value2);
  453.       HTMLRemoveTags(Value2);
  454.       Value2 := AnsiUpperCase(Value2);
  455.       Value := StringReplace(Value, ' '+#13#10, #13#10);
  456.       while Pos(#13#10+#13#10, Value) > 0 do
  457.         Value := StringReplace(Value, #13#10+#13#10, #13#10);
  458.       FullValue:= Value2+': '+Value;
  459.       case GetOption('Awards') of
  460.         1:
  461.           begin
  462.             if GetField(fieldDescription) <> '' then
  463.               Value := GetField(fieldDescription) + #13#10 + #13#10 + Value2 + ': ' + Value
  464.             else
  465.               Value := Value2 + ': ' + Value;
  466.             SetField(fieldDescription, Value);
  467.           end;
  468.         2:
  469.           begin
  470.             if GetField(fieldComments) <> '' then
  471.               Value := GetField(fieldComments) + #13#10 + #13#10 + Value2 + ': ' + Value
  472.             else
  473.               Value := Value2 + ': ' + Value;
  474.             SetField(fieldComments, Value);
  475.           end;
  476.       end;
  477.     end;
  478.   end;
  479. end;
  480.  
  481. // ***** Imports lists like Genre, Country, etc. depending of the selected option *****
  482.  
  483. function ImportList(PageText: string; MultipleValues: Integer; StartTag: string): string;
  484. var
  485.   Value, Value2: string;
  486. begin
  487.   if MultipleValues = 0 then
  488.   begin
  489.     Value := TextBetween(PageText, StartTag, '</a>');
  490.     Value2 := TextAfter(Value, '">');
  491.   end
  492.   else
  493.   begin
  494.     Value := TextBetween(PageText, StartTag, #13#10);
  495.     Value2 := TextBefore(Value, ' <a href="/rg', '');
  496.     if Value2 <> '' then
  497.       Value := Value2;
  498.     Value2 := TextAfter(Value, '">');
  499.     HTMLRemoveTags(Value2);
  500.     if MultipleValues = 1 then
  501.       Value2 := StringReplace(Value2, ' / ', ', ');
  502.   end;
  503.   HTMLDecode(Value2);
  504.   Result := Value2;
  505. end;
  506.  
  507. // ***** functions to import the different pictures kinds, depending of the option selected by user *****
  508.  
  509. function ImportSmallPicture(PageText: string): Boolean;
  510. var
  511.   Value: string;
  512. begin
  513.   Result := False;
  514.   Value := TextBetween(PageText, '<img border="0" alt="cover" src="', '"');
  515.   if Value <> '' then
  516.   begin
  517.     GetPicture(Value);
  518.     Result := True;
  519.   end;
  520. end;
  521.  
  522. function ImportLargePicture(Address: string): Boolean;
  523. var
  524.   Value, Value2: string;
  525. begin
  526.   Result := True;
  527.   Value := GetPage(Address);
  528.   if SearchForLargePicture(Value, 'Onesheet_text', False) then
  529.     Exit;
  530.   if SearchForLargePicture(Value, 'keyart01', True) then
  531.     Exit;
  532.   if SearchForLargePicture(Value, 'keyart02', True) then
  533.     Exit;
  534.   if SearchForLargePicture(Value, 'oster', True) then // poster, usposter, Poster
  535.     Exit;
  536.   if SearchForLargePicture(Value, 'pos01', True) then
  537.     Exit;
  538.   if SearchForLargePicture(Value, 'KeyArt', True) then
  539.     Exit;
  540.   if SearchForLargePicture(Value, 'heet', True) then // Sheet & Onesheet
  541.     Exit;
  542.   if SearchForLargePicture(Value, 'OneSheetv2', True) then
  543.     Exit;
  544.   if SearchForLargePicture(Value, 'artwork', True) then
  545.     Exit;
  546.   if SearchForLargePicture(Value, 'text', True) then
  547.     Exit;
  548.   Address := TextBetween(Value, 'There are ' + #13#10 + '<a href="', '">');
  549.   if Address <> '' then
  550.     Result := ImportLargePicture('http://us.imdb.com' + Address)
  551.   else
  552.     Result := False;
  553. end;
  554.  
  555. function SearchForLargePicture(PageText: string; Name: string; PartialName: Boolean): Boolean;
  556. var
  557.   Value: string;
  558. begin
  559.   Result := False;
  560.   if PartialName then
  561.   begin
  562.     Value := TextBefore(PageText, Name + '.jpg', '/');
  563.     if Value = '' then
  564.       Exit
  565.     else
  566.       Name := Value + Name;
  567.   end;
  568.   Value := TextBefore(PageText, 'th-' + Name + '.jpg', 'src="');
  569.   if Value <> '' then
  570.   begin
  571.     GetPicture(Value + Name + '.jpg');
  572.     Result := True;
  573.   end;
  574. end;
  575.  
  576. function ImportAmazonPicture(PageText: string): Boolean;
  577. var
  578.   Value, Value2: string;
  579. begin
  580.   Result := False;
  581.   Value := TextBefore(PageText, '" title="DVD available', '<a href="');
  582.   if Value = '' then
  583.     Exit;
  584.   PageText := GetPage('http://us.imdb.com' + Value);
  585.   if Pos('unable to find exact matches', PageText) > 0 then
  586.     Exit;
  587.   if Pos('You may also be interested in these items...', PageText) > 0 then
  588.     PageText := TextBefore(PageText, 'You may also be interested in these items...', '');
  589.   Value := TextBefore(PageText, 'TZZZZZZZ.jpg', '<img src="');
  590.   if Value = '' then
  591.     Value := TextBefore(PageText, 'THUMBZZZ.jpg', '<img src="');
  592.   if Value <> '' then
  593.   begin
  594.     GetPicture(Value + 'LZZZZZZZ.jpg');
  595.     Result := True;
  596.   end;
  597. end;
  598.  
  599. //Image from DVD Details Page
  600. function ImportDvdDetailsPicture(PageText: string): Boolean;
  601. var
  602.   Value: string;
  603. begin
  604.   Result := False;
  605.   Value := TextAfter(PageText, '<a href="dvd">DVD details</a>');
  606.   if Value <> '' then
  607.   begin
  608.     Value := GetField(fieldURL);
  609.     PageText := GetPage(Value+'/dvd');
  610.     Value := TextBetween(TextBetween(PageText, 'internetmoviedat">', '></a>'), 'src="', '"');
  611.     if Pos('amazon_logo', Value) = 0 then
  612.     begin
  613.       Value := StringReplace(Value, 'MZZZZZZZ', 'LZZZZZZZ');
  614.       Value := StringReplace(Value, 'TZZZZZZZ', 'LZZZZZZZ');
  615.       Value := StringReplace(Value, '.gif', '.jpg');
  616.       GetPicture(Value);
  617.       Result := True;
  618.     end;
  619.   end;
  620. end;
  621.  
  622. //Image from Merchandising Links (/sales) Page
  623. function ImportMerchandisingPicture(PageText: string): Boolean;
  624. var
  625.   Value: string;
  626. begin
  627.   Result := False;
  628.   Value := TextAfter(PageText, '<a href="sales">');
  629.   if Value <> '' then
  630.   begin
  631.     Value := GetField(fieldURL);
  632.     PageText := GetPage(Value+'/sales');
  633.     Value := TextBetween(PageText, '<img src="http://images.', '"');
  634.     if Value <> '' then
  635.     begin
  636.       Value := StringReplace(Value, 'MZZZZZZZ', 'LZZZZZZZ');
  637.       Value := StringReplace(Value, 'TZZZZZZZ', 'LZZZZZZZ');
  638.       Value := StringReplace(Value, '.gif', '.jpg');
  639.       GetPicture('http://images.'+Value);
  640.       Result := True;
  641.     end;
  642.   end;
  643. end;
  644.  
  645. // ***** Gets summaries for the movie, based on the plot outline given in parameter (that contains the URL to more summaries) *****
  646.  
  647. function ImportSummary(PlotText: string): string;
  648. var
  649.   Address, Value, Value2, PageText, Longest: string;
  650. begin
  651.   Address := TextBetween(PlotText, '<a href="/rg/title-tease/plotsummary', '">(more)</a>');
  652.   if (Address = '') or (GetOption('DescriptionSelection') = 0) then
  653.   begin
  654.     Result := Trim(TextBefore(PlotText, '<a href="/rg', ''));
  655.     if Result = '' then
  656.       Result := Trim(PlotText);
  657.     HTMLRemoveTags(Result);
  658.     HTMLDecode(Result);
  659.   end
  660.   else
  661.   begin
  662.     PageText := GetPage('http://us.imdb.com/rg/title-tease/plotsummary' + Address);
  663.     PickListClear;
  664.     Longest := '';
  665.     Value := TextBetween(PageText, '<p class="plotpar">', '</p>');
  666.     PageText := RemainingText;
  667.     while Value <> '' do
  668.     begin
  669.       Value := StringReplace(Value, #13#10, ' ');
  670.       Value := StringReplace(Value, '<br>', #13#10);
  671.       HTMLRemoveTags(Value);
  672.       HTMLDecode(Value);
  673.       while Pos('  ', Value) > 0 do
  674.         Value := StringReplace(Value, '  ', ' ');
  675.       if Length(Value) > Length(Longest) then
  676.         Longest := Value;
  677.       PickListAdd(Trim(Value));
  678.       Value := TextBetween(PageText, '<p class="plotpar">', '</p>');
  679.       PageText := RemainingText;
  680.     end;
  681.     if (GetOption('BatchMode') > 0) or (GetOption('DescriptionSelection') = 2) then
  682.       Result := Longest
  683.     else
  684.     begin
  685.       if not PickListExec('Select a description for "' + GetField(fieldOriginalTitle) + '"', Result) then
  686.         Result := '';
  687.     end;
  688.   end;
  689. end;
  690.  
  691. // ***** beginning of the program *****
  692.  
  693. begin
  694.   if CheckVersion(3,5,0) then
  695.   begin
  696.     MovieName := '';
  697.     if GetOption('BatchMode') = 2 then
  698.     begin
  699.       MovieName := GetField(fieldURL);
  700.       if Pos('imdb.com', MovieName) = 0 then
  701.         MovieName := '';
  702.     end;
  703.     if MovieName = '' then
  704.       MovieName := GetField(fieldOriginalTitle);
  705.     if MovieName = '' then
  706.       MovieName := GetField(fieldTranslatedTitle);
  707.     if GetOption('BatchMode') = 0 then
  708.     begin
  709.       if not Input('IMDB Import', 'Enter the title or the IMDB URL of the movie:', MovieName) then
  710.         Exit;
  711.     end
  712.     else
  713.       Sleep(500);
  714.     if MovieName <> '' then
  715.     begin
  716.       if Pos('imdb.com', MovieName) > 0 then
  717.         AnalyzeResultsPage(MovieName)
  718.       else
  719.       begin
  720.         MovieName := StringReplace(MovieName, '&', 'and');
  721.         if (GetOption('BatchMode') > 0) or (GetOption('PopularSearches') = 1) then
  722.           AnalyzeResultsPage('http://us.imdb.com/find?tt=1;q=' + UrlEncode(MovieName))
  723.         else
  724.           AnalyzeResultsPage('http://us.imdb.com/find?more=tt;q=' + UrlEncode(MovieName));
  725.       end;
  726.     end;
  727.   end
  728.   else
  729.     ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.5.0)');
  730. end.
  731.